/*
 * Programa
 */

#include"ParserParametros.h"
#include "utiles.h"
#include "Base64.h"



int main(int argc,char** argv){
	FILE *f1,*f2;
	int continuar,eof1,eof2;
	int readSize;
	char *buffer,*file1,*file2;
	char op;
	char returnString[5];
	int errno = 0;
	f1=f2=NULL;
	file1=file2=NULL;
	op = END_OF_STRING;
	readSize = 0;
	returnString[5] = '\0';

	eof1=eof2=0;
	continuar=1;
	buffer=NULL;
	convertirEntrada(argc,argv,&op,&file1,&file2);

	//If no operation is set exit
	if(op == END_OF_STRING){
		printf(ERROR_PARAMETROS);
		return -1;
	}

	if (abrirArchivos(argc,argv,&f1,&f2,file1,file2) < 0)
		return -1;

	//Obtengo la clave valor del archivo 1

	if (eof1 ==EOF) {
		free(buffer);
		exit(-1);
	}

	//Make the operation, encode or decode
	switch (op) {
		case 'e':
			errno = b64_encode(f1,f2);
			break;
		case 'd':
			errno = b64_decode(f1,f2);
			break;
	}

	if(errno == B64_CHARACTER_INVAL){
		fprintf(stderr,"%s","\nHubo un caracter invalido...\nFin del proceso\n");
		exit(-1);
	}


	fclose(f1);
	fclose(f2);

	return 0;

}

